package com.apes.scm.masterdata.finance.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 定义收入类型
 * @author yiny
 * @create 2018.8.13 11:47
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name=IncomeType.CONST_TABLE_NAME)
public class IncomeType extends Model {
    public static final String CONST_TABLE_NAME = "mas_income_type";

    @Id
    @Column(name="id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "定义收入类型", padding = 3)
    @Comment("收入类型编码")
    private String id; // 收入类型编码

    @Column(name = "name", nullable = false)
    @Comment("收入类型名称")
    private String name; // 收入类型名称

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id")
    @Comment("税率编码")
    private Tax tax;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "in_come_category", referencedColumnName = "id")
    @Comment("收入类别")
    private Enumeration inComeCategory; // 收入类别（rebate：返利；cost：费用；margin：保证金；miscellaneousIncome：杂项收入）

    /***
     * 与计算基数合并
     * esb-2842
     */
//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "calculation_method", referencedColumnName = "id")
//    @Comment("计算方法")
//    private Enumeration calculationMethod; // 计算方法（manualInput：手工输入；fixedAmount：固定金额；automaticCalculation：自动计算）

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "charge_interval", referencedColumnName = "id")
    @Comment("收取间隔")
    private Enumeration chargeInterval; // 收取间隔（atAnyTime：随时；perMonth：每月；eachQuarter：每季度；everyHalfYear：每半年；perYear：每年）

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "calculation_base", referencedColumnName = "id")
    @Comment("计算基数")
    private Enumeration calculationBase; // 计算基数(purchaseAmount:采购金额; purchaseQuantity:采购数量; salesAmount:销售金额; salesVolume:销售数量; paymentAmount:付款金额;fixedAmount：固定金额)

    @Column(name = "invoice_valid", nullable = false, columnDefinition = "number(1, 0) default 0")
    @Comment("是否开票")
    private boolean invoiceValid;
    /***
     * 删除字段
     */
//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "scale_back_category", referencedColumnName = "id")
//    @Comment("规规模返类别")
//    private Enumeration scaleBackCategory; // 规规模返类别（ordinaryRebate:普通返利; regain:达量返; stepBack:阶梯返）

    @Column(name = "pin_Yin_Ma", length = 64)
    @Comment("拼音码")
    private String pinYinMa; // 拼音码

    @Column(name = "valid", nullable = false, columnDefinition = "number(1, 0) default 1")
    @Comment("有效标记")
    private boolean valid; // 有效标记

    @Column(name = "platform_valid", nullable = false, columnDefinition = "number(1, 0) default 1")
    @Comment("平台费用有效标记")
    private boolean platformValid; // 有效标记

    @Column(name = "supplier_valid", nullable = false, columnDefinition = "number(1, 0) default 1")
    @Comment("供应商有效标记")
    private boolean supplierValid; // 有效标记

}
